/* eslint-disable no-return-assign */
import React, { Component } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Table, Tag } from 'antd';
import moment from "moment"

const columns = [
    {
        title: '标题',
        dataIndex: 'title',
        sorter: (a, b) => a.title.length - b.title.length,
        width: 400,
        // defaultSortOrder: 'descend',
    },
    {
        title: '类型',
        dataIndex: 'infoTypeName',
        width: 200,
    },
    {
        title: '创建时间',
        dataIndex: 'createTime',
        render: text => <Tag color="success">{moment(text).format("YYYY-MM-DD")}</Tag>,
    },
];

class Page extends Component {
    constructor(props) {
        super(props);
        this.state = {
            arr: [],
        }
        fetch("/api/info/InfoList", {
            method: 'POST',
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
                page: 1,
                limit: 50,
            })
        }).then(r => r.json())
            .then(({ result, success }) => {
                if (success) {
                    const { count, arr } = result;
                    this.setState({
                        arr: arr.map(item => ({ ...item, key: item.id })),
                    })
                }
            })
    }
    render() {
        console.log(this.state)
        return (
            <PageHeaderWrapper>
                <Table
                    scroll={{ y: 240 }}
                    pagination={{ pageSize: 50 }}
                    rowSelection={true}
                    expandable={{
                        expandedRowRender: record => <p style={{ margin: 0 }}>{record.bodySub}</p>,
                        // rowExpandable: record => record.name !== 'Not Expandable',
                    }}
                    dataSource={this.state.arr} columns={columns} />
            </PageHeaderWrapper>
        );
    }
}
export default Page;
